<?php
/*
 * 后台权限管理模块管理
 */
class Adminnode extends CI_Controller
{
	function __construct(){
		parent::__construct();
		$admin_id = $this->session->userdata('admin_id');
        if ( empty($admin_id ) ) {
			$this->load->helper('url');
        	redirect('login/index','refresh');
        }
        power($admin_id);
    }
    /*
     * 权限管理模块列表
     */
	function index()
	{
        $where = array();
		$total_rows = $this->db->like($where)->from('admin_node')->count_all_results();
		$per_page = 10;
		$this->load->library('page',array('total'=>$total_rows,'perpage'=>$per_page));
		$data['page'] = $this->page->show(1);
		$this->load->model('admin_model','mAdmin',TRUE);
        $data['results'] = $this->mAdmin->get_admin_list($per_page,$this->page->offset(),$where);
        $this->load->view('adminnode/index', $data);
	}
	/*
	 * 权限管理模块添加
	 */
	function add()
	{
		if ( !is_post() ){
			$this->load->view('adminnode/add');
		}else{
			$this->db->insert('admin_node', $_POST);
			$last_id = $this->db->insert_id();
			if ( $last_id>0 ){
				display('添加成功',site_url("adminnode/add"));
			}else{
				display('添加失败',site_url("adminnode/add"),0);
			}
		}
	}
	/*
	 * 权限管理模块修改
	 */
	function edit($id)
	{
		if ( !is_post() ){
			$query = $this->db->from("admin_node")->where('id', $id)->get();
			$data['row'] = $query->row();
			$this->load->view('adminnode/edit', $data);
		}else{
			$this->db->where('id',$id);
			$this->db->update('admin_node', $_POST);
			$affected_rows = $this->db->affected_rows();
			if ( $affected_rows>0 ){
				display('修改成功',site_url("adminnode/edit/{$id}"));
			}else{
				display('修改失败',site_url("adminnode/edit/{$id}"),0);
			}
		}
	}
	/*
	 * 权限管理模块删除
	 */
	function delete($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('admin_node');
		display('删除成功',site_url("adminnode/index"));
	}
}
?>
